﻿using System;
using System.Windows;
using System.Windows.Controls;
using Resn.WhuPub.BIL;

namespace Resn.WhuPub.WPFClientUI
{
        /// <summary>
        /// CreateDepartmentWindow.xaml 的交互逻辑
        /// </summary>
        public partial class CreateDepartmentPage : Page
        {
                private readonly GlobalManager gm = GlobalManager.Instance;


                public CreateDepartmentPage()
                {
                        InitializeComponent();
                }

                public String DepartmentName { get; set; }


                private void Page_Loaded(object sender, RoutedEventArgs e)
                {
                        LayoutRoot.DataContext = this;

                        CorporateBranchNameTextBlock.Text = gm.CorporateBranch.Name;
                }

                private void AcceptButton_Click(object sender, RoutedEventArgs e)
                {
                        if (String.IsNullOrEmpty(DepartmentName))
                        {
                                MessageBox.Show("部门名称不能为空");
                                return;
                        }

                        try
                        {
                                IDepartment department = gm.CorporateBranch.CreateDepartment(DepartmentName);
                                department.Insert();
                        }
                        catch (Exception ex)
                        {
                                MessageBox.Show(ex.Message);
                                return;
                        }

                        finally
                        {
                        }

                        NavigationService.Navigate(new Uri("ManageDepartmentsPage.xaml", UriKind.Relative));
                }


                private void CancelButton_Click(object sender, RoutedEventArgs e)
                {
                        NavigationService.Navigate(new Uri("ManageDepartmentsPage.xaml", UriKind.Relative));
                }
        }
}